package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursingLevel")
@Api(tags = "护理等级管理")
public class NursingLevelController {
    @Autowired
    NursingLevelService nursingLevelService;
    /**
     * 3.1 查询所有护理等级
     * 接口地址:/nursingLevel/listAll
     * 请求方式:GET
     * 请求参数:无
     */
    @GetMapping("/listAll")
    @ApiOperation(value = "查询所有护理等级")
    public ResponseResult listAll(){
         List<NursingLevelVo> allPlan = nursingLevelService.getAllPlan();
         return ResponseResult.success(allPlan);
    }
    /**
     * 3.2 新增
     * 接口地址:/nursingLevel/insert
     * 请求方式:POST
     * 请求示例:
     */
    @ApiOperation(value = "新增护理等级")
    @PostMapping("/insert")
    public ResponseResult insert(@RequestBody NursingLevelVo nursingLevelVo){
        nursingLevelService.addNursingLevel(nursingLevelVo);
        return ResponseResult.success();
    }
    /**
     *3.3 条件分页查询
     * 接口地址:/nursingLevel/listByPage
     * 请求方式:GET
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "护理姓名", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "状态", required = false, dataType = "int", paramType = "query")
    })
    @GetMapping("/listByPage")
    @ApiOperation("护理等级分页查询")
    public ResponseResult<PageResponse<NursingLevelVo>> selectByPageLevel(
            Integer pageNum,
            Integer pageSize,
            String name,
            Integer status
    ){
        PageResponse<NursingLevelVo> ooo = nursingLevelService.getByPagePlan(name, status, pageNum, pageSize);
        return ResponseResult.success(ooo);
    }
    /**
     *3.4 根据id查询护理等级
     * 接口地址:/nursingLevel/{id}
     * 请求方式:GET
     */
    @ApiOperation("根据id查询护理等级")
    @GetMapping("/{id}")
    public ResponseResult<NursingLevelVo> getById(@PathVariable Long id){
        NursingLevelVo nursingLevelVo = nursingLevelService.getById(id);
        return ResponseResult.success(nursingLevelVo);
    }
    /**
     *3.5 修改
     * 接口地址:/nursingLevel/update
     * 请求方式:PUT
     */
    @ApiOperation("修改")
    @PutMapping("/update")
    public ResponseResult update(@RequestBody NursingLevelVo nursingLevelVo){
        nursingLevelService.updateNursingLevel(nursingLevelVo);
        return ResponseResult.success();
    }
    /**
     *3.6 删除
     * 接口地址:/nursingLevel/{id}
     * 请求方式:DELETE
     */
    @ApiOperation("删除")
    @DeleteMapping("/delete/{id}")
    public ResponseResult deleteById(@PathVariable Long id){
        nursingLevelService.deleteNursingLevelById(id);
        return ResponseResult.success();
    }
    /**
     * 3.7 启用禁用
     * 接口地址:/nursingLevel/{id}/status/{status}
     * 请求方式:PUT
     * 请求参数:
     */
    @ApiOperation("启用禁用")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult updateStatus(@PathVariable Long id, @PathVariable Integer status){
        nursingLevelService.sdd(id, status);
        return ResponseResult.success();
    }

}
